<template>
  <div>
    <!-- 头部区域 -->
    <div style="height: 60px; line-height: 60px; background-color: white; margin-bottom: 2px; display: flex">
      <div style="width: 300px">
        <img src="@/assets/logo.png" alt="" style="width: 40px; position: relative; top: 10px; left: 20px">
        <span style="margin-left: 25px; font-size: 24px">德州农林害虫资源库</span>
      </div>
      <div style="flex: 1; text-align: right; padding-right: 20px">
        <el-dropdown size="medium">
          <span class="el-dropdown-link" style="cursor: pointer">
            {{ admin.username }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown" style="margin-top: -5px">
            <el-dropdown-item>
              <div style="width: 50px; text-align: center;" @click="logout">退出</div>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>

    <!-- 侧边栏和主体 -->
    <div style="display: flex">
      <!-- 侧边栏导航 -->
      <div
        style="width: 200px; min-height: calc(100vh - 62px); overflow: hidden; margin-right: 2px; background-color: white">
        <el-menu :default-active="$route.path" router class="el-menu-demo" style="margin-bottom: 10px">
          <el-menu-item index="/">
            <i class="el-icon-s-home"></i>
            <span>首页</span>
          </el-menu-item>


          <el-submenu index="insect">
            <template slot="title">
              <i class="el-icon-s-operation"></i>
              <span>校园昆虫板块</span>
            </template>

            <el-menu-item index="/insectList">
              <li><i class="el-icon-zoom-in"></i> 校园昆虫</li>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="goods">
            <template slot="title">
              <i class="el-icon-notebook-1"></i>
              <span>校园植物板块</span>
            </template>

            <el-menu-item index="/plantList">
              <li><i class="el-icon-orange"></i> 校园植物</li>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="/verminList ">
            <template slot="title">
              <i class="el-icon-aim"></i>
              <span>常见害虫板块</span>
            </template>

            <el-menu-item index="/verminDetection">
              <li><i class="el-icon-upload"></i> 常见害虫检测</li>
            </el-menu-item>
            <el-menu-item index="/verminList">
              <li><i class="el-icon-warning"></i> 常见害虫列表</li>
            </el-menu-item>
            <el-menu-item index="/addPest">
              <li><i class="el-icon-circle-plus-outline"></i>害虫添加</li>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="category">
            <template slot="title">
              <i class="el-icon-s-operation"></i>
              <span>害虫分类管理</span>
            </template>
            <el-menu-item index="/addCategory">害虫分类添加</el-menu-item>
            <el-menu-item index="/categoryList">害虫分类列表</el-menu-item>
          </el-submenu>
          <el-submenu index="admin">
            <template slot="title">
              <i class="el-icon-user"></i>
              <span>管理员管理</span>
            </template>
            <el-menu-item index="/addAdmin">管理员添加</el-menu-item>
            <el-menu-item index="/adminList">管理员列表</el-menu-item>
          </el-submenu>


        </el-menu>
      </div>

      <div style="flex: 1; width: 0; background-color: white; padding: 10px">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script>
import Cookies from 'js-cookie'

export default {
  name: "Layout.vue",
  data() {
    return {
      admin: Cookies.get('admin') ? JSON.parse(Cookies.get('admin')) : {}
    }
  },
  methods: {
    logout() {
      // 清除浏览器用户数据
      Cookies.remove('admin')
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped></style>
